package org.ume.school.modules.model.entity;

import org.ume.school.modules.utils.TimeUtils;
import org.apache.commons.lang3.StringUtils;

import javax.persistence.*;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * Created by Django on 2017/7/19.
 */
@Entity
@Table(name = "vshop_goods_storehouse")
public class Goods implements Serializable {


    @Column(name = "id", columnDefinition = "varchar(64) NOT NULL")
    @Id
    private String id;

    @Column(name = "title", columnDefinition = "varchar(1024) DEFAULT NULL")
    private String title;

    /**
     * 1 随笔  2 散文 3 诗词 4 小说
     */
    @Column(name = "type", columnDefinition = "varchar(64) DEFAULT NULL COMMENT '类型'")
    private String type;

    /**
     * 创作时间
     */
    @Column(name = "create_time", columnDefinition = "datetime DEFAULT NULL")
    private Date createTime;

    /**
     * 作者ID，如果是原创，否则为空
     */
    @Column(name = "user_id", columnDefinition = "varchar(255) DEFAULT NULL")
    private String userId;

    /**
     * 作者名称
     */
    @Column(name = "user_name", columnDefinition = "varchar(255) DEFAULT NULL")
    private String userName;

    /**
     * 摘要，序
     */
    @Column(name = "summary", columnDefinition = "varchar(2048) DEFAULT NULL")
    private String summary;

    /**
     * 标签
     */
    @Column(name = "tags", columnDefinition = "varchar(1024) DEFAULT NULL")
    private String tags;

    /**
     * 来源： 本站  其他网站
     */
    @Column(name = "source", columnDefinition = "varchar(1024) DEFAULT NULL")
    private String source;

    //浏览次数
    @Column(name = "pvs", columnDefinition = "INT default 0")
    private Integer pvs = 0;

    //状态，0 待审核  1 审核成功 2 下架
    @Column(name = "status", columnDefinition = "INT default 0")
    private Integer status = 0;

    //点赞次数
    @Column(name = "greats", columnDefinition = "INT default 0")
    private Integer greats = 0;


    /**
     * 文章内容
     */
    @Column(name = "content", columnDefinition = "text")
    private String content;

    //文章封面图
    @Column(name = "image", columnDefinition = "varchar(255) DEFAULT NULL")
    private String image;

    /**
     * 放置位置： 1 ： 置顶  2： 滚动区  4: 广告 :
     */
    @Column(name = "place", columnDefinition = "INT default 0")
    private Integer place = 0;

    @Transient
    private List<String> tagList = new ArrayList<>();

    @Column(name = "user_head_image", columnDefinition = "varchar(128) DEFAULT NULL")
    private String userHeadImage;  // 作者头像

    @Column(name = "nick_name", columnDefinition = "varchar(64) DEFAULT NULL")
    private String nickName;  //昵称

    //总评论数
    @Column(name = "comment_cnt", columnDefinition = "INT default 0")
    private Integer commentCnt = 0;

    @Transient
    private String sdate;

    public String getImage() {
        return image;
    }

    public void setImage(String image) {
        this.image = image;
    }

    public String getSdate() {
        if (null != this.getCreateTime()) {
            sdate = TimeUtils.parseNLPattern(this.getCreateTime());
        }
        return sdate;
    }

    public void setSdate(String sdate) {
        this.sdate = sdate;
    }

    public List<String> getTagList() {
        tagList.clear();
        if (!StringUtils.isEmpty(tags)) {
            String[] tagss = tags.split("#");
            for (String t : tagss) {
                if (!StringUtils.isEmpty(t)) {
                    tagList.add(t);
                }
            }
        }
        return tagList;
    }

    public void setTagList(List<String> tagList) {
        this.tagList = tagList;
    }

    public Goods() {
    }

    public Goods(String id, String content) {
        this.id = id;
        this.content = content;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getSummary() {
        return summary;
    }

    public void setSummary(String summary) {
        this.summary = summary;
    }

    public String getTags() {
        return tags;
    }

    public void setTags(String tags) {
        this.tags = tags;
    }

    public String getSource() {
        return source;
    }

    public void setSource(String source) {
        this.source = source;
    }

    public Integer getPvs() {
        return pvs;
    }

    public void setPvs(Integer pvs) {
        this.pvs = pvs;
    }

    public Integer getGreats() {
        return greats;
    }

    public void setGreats(Integer greats) {
        this.greats = greats;
    }

    public String getUserHeadImage() {
        return userHeadImage;
    }

    public void setUserHeadImage(String userHeadImage) {
        this.userHeadImage = userHeadImage;
    }

    public String getNickName() {
        return nickName;
    }

    public void setNickName(String nickName) {
        this.nickName = nickName;
    }

    public Integer getCommentCnt() {
        return commentCnt;
    }

    public void setCommentCnt(Integer commentCnt) {
        this.commentCnt = commentCnt;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }
}
